package com.fanhao.dllo.justforyou.fragment;

import android.content.Context;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;

import com.fanhao.dllo.justforyou.R;
import com.fanhao.dllo.justforyou.adapter.JokeAdapter;

public class JokeFragment extends Fragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private JokeAdapter jokeAdapter;


    @Override
    public void onAttach(Context context) {

        super.onAttach(context);
    }


    /***
     * 在这个方法里,获取传入的数据
     * */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }

/**
 * 在这个方法里,绑定布局
 */
    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_joke,null);
        return v;
    }

    /**
    * 在这个方法里,初始化组件
    * **/

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        // 移动条的颜色
        tabLayout.setSelectedTabIndicatorColor(0xffff6091);
        // tabLayout可滑动模式
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        viewPager = (ViewPager) view.findViewById(R.id.viewPage);

    }


    /**
     * 在这个方法里,初始化数据
     * **/
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // 初始化adapter
        jokeAdapter = new JokeAdapter(getChildFragmentManager());
        //viewPage绑定adapter
        viewPager.setAdapter(jokeAdapter);
        //tabLayout绑定viewPage
        tabLayout.setupWithViewPager(viewPager);


    }
}
